package me.xADudex.RandomLocation;

import org.bukkit.command.*;
import org.bukkit.entity.*;
import java.util.*;
import org.bukkit.*;
import com.wimbli.WorldBorder.*;
import org.bukkit.inventory.*;

class CmdHandler
{
    private Main pl;
    
    CmdHandler(final Main main) {
        this.pl = main;
    }
    
    void onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
        if (label.equalsIgnoreCase("rLoc")) {
            if (sender.hasPermission("RandomLocation.Admin")) {
                if (args.length == 0) {
                    sender.sendMessage(ChatColor.DARK_GRAY + "------------ " + ChatColor.GREEN + "随机传送 " + ChatColor.DARK_GRAY + "------------");
                    sender.sendMessage(ChatColor.DARK_GRAY + "作者: " + ChatColor.GREEN + "暗淡");
                    sender.sendMessage(ChatColor.DARK_GRAY + "版本: " + ChatColor.GREEN + this.pl.getDescription().getVersion());
                    sender.sendMessage(ChatColor.DARK_GRAY + "指令: " + ChatColor.GREEN + " /rPlayer, /rReload, /rSpawn");
                    sender.sendMessage(ChatColor.DARK_GRAY + "子命令:         " + ChatColor.GREEN + "(use /rLoc in front)");
                    sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "create <Name> - 创建一个区域");
                    sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "pos1/2 <Name> [x y z]- 设置点1/点2");
                    sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "radius <Name> <#Radius> - 使用半径设置点1/点2");
                    sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "fitWorldBorder <ZoneName> - 根据世界边界设置一个区域");
                    sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "option <ZoneName> <Option> <Value> - 修改设置");
                    sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setType <Name> <Teleport/Portal/NonTeleport> - 设置类型");
                    sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setPortalDest <Name> <PortalDest> - 设置目标点");
                    sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "del <ZoneName> - 删除区域");
                    sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "list - 查看区域列表");
                }
                else if (args[0].equalsIgnoreCase("create")) {
                    if (args.length == 2) {
                        if (this.pl.zoneManager.createZone(args[1])) {
                            String coords = "(0,0,0)";
                            if (sender instanceof Player) {
                                final Player p = (Player)sender;
                                this.pl.zoneManager.setPos(args[1], p.getLocation(), true);
                                this.pl.zoneManager.setPos(args[1], p.getLocation(), false);
                                coords = "(" + p.getLocation().getBlockX() + ", " + p.getLocation().getBlockY() + ", " + p.getLocation().getBlockZ() + ")";
                            }
                            sender.sendMessage(ChatColor.GREEN + "Created zone \"" + args[1] + "\" at " + coords + " in world: \"" + this.pl.zoneManager.getZone(args[1]).getWorld().getName() + "\"");
                            sender.sendMessage(ChatColor.GREEN + "Do /rLoc option " + args[1] + " info to see info about the zone");
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Could not create zone. A zone by simular name exists");
                        }
                    }
                    else {
                        sender.sendMessage(ChatColor.GREEN + "Use /rLoc create <ZoneName>");
                    }
                }
                else if (args[0].equalsIgnoreCase("pos1")) {
                    if (sender instanceof Player) {
                        final Player p2 = (Player)sender;
                        if (args.length == 2) {
                            final String zn = this.pl.zoneManager.setPos(args[1], p2.getLocation(), true);
                            if (zn != null) {
                                p2.sendMessage(ChatColor.GREEN + "Successfully set pos1 for zone " + zn + " (" + p2.getLocation().getBlockX() + "," + p2.getLocation().getBlockY() + "," + p2.getLocation().getBlockZ() + ")");
                            }
                            else {
                                p2.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else if (args.length == 5) {
                            int x = 0;
                            int y = 0;
                            int z = 0;
                            try {
                                x = Integer.parseInt(args[2]);
                            }
                            catch (NumberFormatException e) {
                                sender.sendMessage(ChatColor.GREEN + "\"" + args[2] + "\" is not a number!");
                                return;
                            }
                            try {
                                y = Integer.parseInt(args[3]);
                            }
                            catch (NumberFormatException e) {
                                sender.sendMessage(ChatColor.GREEN + "\"" + args[2] + "\" is not a number!");
                                return;
                            }
                            try {
                                z = Integer.parseInt(args[4]);
                            }
                            catch (NumberFormatException e) {
                                sender.sendMessage(ChatColor.GREEN + "\"" + args[2] + "\" is not a number!");
                                return;
                            }
                            final Zone zone = this.pl.zoneManager.getZone(args[1]);
                            if (zone != null) {
                                final Location loc = new Location(zone.getWorld(), (double)x, (double)y, (double)z);
                                zone.setPos(loc, true);
                                p2.sendMessage(ChatColor.GREEN + "Successfully set pos1 for zone " + zone.getName() + " (" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ")");
                            }
                            else {
                                p2.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            p2.sendMessage(ChatColor.GREEN + "Use /rLoc pos1 <ZoneName>");
                        }
                    }
                    else {
                        sender.sendMessage("You have to be a player to use that command");
                    }
                }
                else if (args[0].equalsIgnoreCase("pos2")) {
                    if (sender instanceof Player) {
                        final Player p2 = (Player)sender;
                        if (args.length == 2) {
                            final String zn = this.pl.zoneManager.setPos(args[1], p2.getLocation(), false);
                            if (zn != null) {
                                p2.sendMessage(ChatColor.GREEN + "Successfully set pos2 for zone " + zn + " (" + p2.getLocation().getBlockX() + "," + p2.getLocation().getBlockY() + "," + p2.getLocation().getBlockZ() + ")");
                            }
                            else {
                                p2.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else if (args.length == 5) {
                            int x = 0;
                            int y = 0;
                            int z = 0;
                            try {
                                x = Integer.parseInt(args[2]);
                            }
                            catch (NumberFormatException e) {
                                sender.sendMessage(ChatColor.GREEN + "\"" + args[2] + "\" is not a number!");
                                return;
                            }
                            try {
                                y = Integer.parseInt(args[3]);
                            }
                            catch (NumberFormatException e) {
                                sender.sendMessage(ChatColor.GREEN + "\"" + args[2] + "\" is not a number!");
                                return;
                            }
                            try {
                                z = Integer.parseInt(args[4]);
                            }
                            catch (NumberFormatException e) {
                                sender.sendMessage(ChatColor.GREEN + "\"" + args[2] + "\" is not a number!");
                                return;
                            }
                            final Zone zone = this.pl.zoneManager.getZone(args[1]);
                            if (zone != null) {
                                final Location loc = new Location(zone.getWorld(), (double)x, (double)y, (double)z);
                                zone.setPos(loc, false);
                                p2.sendMessage(ChatColor.GREEN + "Successfully set pos1 for zone " + zone.getName() + " (" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ")");
                            }
                            else {
                                p2.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            p2.sendMessage(ChatColor.GREEN + "Use /rLoc pos2 <ZoneName>");
                        }
                    }
                    else {
                        sender.sendMessage("You have to be a player to use that command");
                    }
                }
                else if (args[0].equalsIgnoreCase("radius")) {
                    if (sender instanceof Player) {
                        final Player p2 = (Player)sender;
                        if (args.length == 3) {
                            int radius;
                            try {
                                radius = Integer.parseInt(args[2]);
                            }
                            catch (Exception e2) {
                                p2.sendMessage(ChatColor.GREEN + "\"" + args[2] + "\" is not a valid number");
                                return;
                            }
                            final String zn2 = this.pl.zoneManager.setPos(args[1], p2.getLocation().add((double)radius, (double)radius, (double)radius), true);
                            if (zn2 != null) {
                                this.pl.zoneManager.setPos(args[1], p2.getLocation().add((double)(-radius), (double)(-radius), (double)(-radius)), false);
                                String s = "";
                                if (radius != 0) {
                                    s = "s";
                                }
                                p2.sendMessage(ChatColor.GREEN + "Successfully set pos1 & pos2 for zone " + zn2 + " " + radius + " block" + s + " from you");
                            }
                            else {
                                p2.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            p2.sendMessage(ChatColor.GREEN + "Use /rLoc radius <ZoneName> <#Radisu>");
                        }
                    }
                    else {
                        sender.sendMessage("You have to be a player to use that command");
                    }
                }
                else if (args[0].equalsIgnoreCase("fitWorldBorder")) {
                    if (this.pl.isWorldBorderInstalled()) {
                        if (args.length == 2) {
                            final Zone z2 = this.pl.zoneManager.getZone(args[1]);
                            if (z2 != null) {
                                if (z2.getWorld() != null) {
                                    final BorderData border = Config.Border(z2.getWorld().getName());
                                    if (border != null) {
                                        boolean round = false;
                                        if (border.getShape() != null) {
                                            round = border.getShape();
                                        }
                                        else {
                                            round = Config.ShapeRound();
                                        }
                                        if (round) {
                                            double xwalk = 1.0;
                                            double zwalk = 1.0;
                                            int maxR = 0;
                                            if (border.getRadiusX() > border.getRadiusZ()) {
                                                xwalk = border.getRadiusX() / border.getRadiusZ();
                                                maxR = border.getRadiusX();
                                            }
                                            else {
                                                zwalk = border.getRadiusZ() / border.getRadiusX();
                                                maxR = border.getRadiusZ();
                                            }
                                            Location max = new Location(z2.getWorld(), border.getX() + border.getRadiusX(), 255.0, border.getZ() + border.getRadiusZ());
                                            Location min = new Location(z2.getWorld(), border.getX() - border.getRadiusX(), 0.0, border.getZ() - border.getRadiusZ());
                                            boolean succeed = false;
                                            for (int i = -1; i < maxR; ++i) {
                                                if (border.insideBorder(max) && border.insideBorder(min)) {
                                                    z2.setPos(max, true);
                                                    z2.setPos(min, false);
                                                    succeed = true;
                                                    break;
                                                }
                                                max = max.subtract(xwalk, 0.0, zwalk);
                                                min = min.add(xwalk, 0.0, zwalk);
                                            }
                                            if (succeed) {
                                                sender.sendMessage(ChatColor.GREEN + "Successfully fited zone " + z2.getName() + " to the world border");
                                                sender.sendMessage(ChatColor.GREEN + "As best as possible as it is round");
                                                sender.sendMessage(ChatColor.GREEN + "For the world " + z2.getWorld().getName() + " (" + max.getBlockX() + "." + max.getBlockY() + "," + max.getBlockZ() + ")(" + min.getBlockX() + "," + min.getBlockY() + "," + min.getBlockZ() + ")");
                                            }
                                            else {
                                                sender.sendMessage(ChatColor.GREEN + "Was not able to fit the zone " + z2.getName() + " to the");
                                                sender.sendMessage(ChatColor.GREEN + "World border for world " + z2.getWorld().getName() + "!");
                                            }
                                        }
                                        else {
                                            final Location max2 = new Location(z2.getWorld(), border.getX() + border.getRadiusX(), 255.0, border.getZ() + border.getRadiusZ());
                                            final Location min2 = new Location(z2.getWorld(), border.getX() - border.getRadiusX(), 0.0, border.getZ() - border.getRadiusZ());
                                            z2.setPos(max2, true);
                                            z2.setPos(min2, false);
                                            sender.sendMessage(ChatColor.GREEN + "Successfully fited zone " + z2.getName() + " to the world border");
                                            sender.sendMessage(ChatColor.GREEN + "For the world " + z2.getWorld().getName() + " (" + max2.getBlockX() + "." + max2.getBlockY() + "," + max2.getBlockZ() + ")(" + min2.getBlockX() + "," + min2.getBlockY() + "," + min2.getBlockZ() + ")");
                                        }
                                    }
                                    else {
                                        sender.sendMessage(ChatColor.GREEN + "The world " + z2.getWorld().getName() + " for the zone " + z2.getName() + " does not got a border!");
                                    }
                                }
                                else {
                                    sender.sendMessage(ChatColor.GREEN + "The world for the zone " + z2.getName() + " is not loaded!");
                                }
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc fitWorldBorder <ZoneName>");
                        }
                    }
                    else {
                        sender.sendMessage(ChatColor.GREEN + "WorldBorder must be installed for this command to work!");
                    }
                }
                else if (args[0].equalsIgnoreCase("option")) {
                    if (args.length == 1 || args.length == 2) {
                        sender.sendMessage(ChatColor.DARK_GRAY + "------------ " + ChatColor.GREEN + "RandomLocation " + ChatColor.DARK_GRAY + "------------");
                        sender.sendMessage(ChatColor.DARK_GRAY + "Author: " + ChatColor.GREEN + "xADudex aka xGamingDudex");
                        sender.sendMessage(ChatColor.DARK_GRAY + "Version: " + ChatColor.GREEN + this.pl.getDescription().getVersion());
                        sender.sendMessage(ChatColor.DARK_GRAY + "Commands:         (use /rLoc option <ZoneName> in front)");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "info - See info about the zone");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setPerm <CustomPerm> - Set custom perm for zone");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "useRange <true/false> - Enable/Disable range");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setRange <#Range> - Set range");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setRangeFrom <Zone/Custom> - Set where range is from");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setCustomRangeLocation - Set where custom range is from");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "keepDirection <true/false> - Enable/Disable keepDrection");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "mode <ground/air/top> - Set spawn mode");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setGroundBlocks <1,2,3...> - List blocks to spawn on");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setTopBlocks <1,2,3...> - List blocks to spawn under");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setInvulnerability <Seconds> - Set invulnerability");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setUseKit <true/false> - Give chest kit on teleport");
                        sender.sendMessage(ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "setKit - Set the given chest kit");
                    }
                    else if (args[2].equalsIgnoreCase("info")) {
                        final String info = this.pl.zoneManager.getInfo(args[1]);
                        if (info != null) {
                            sender.sendMessage(info);
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                        }
                    }
                    else if (args[2].equalsIgnoreCase("setPerm")) {
                        if (args.length == 4) {
                            final String zn3 = this.pl.zoneManager.setPerm(args[1], args[3]);
                            if (zn3 != null) {
                                if (args[3].equalsIgnoreCase("none")) {
                                    sender.sendMessage(ChatColor.GREEN + "Disabled custom permission for zone " + zn3);
                                }
                                else {
                                    sender.sendMessage(ChatColor.GREEN + "Successfully set custom perm for zone " + zn3 + " to " + "RandomLocation." + args[3]);
                                }
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> perm <Permission>");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("useRange")) {
                        if (args.length == 4) {
                            boolean flag = false;
                            if (args[3].equalsIgnoreCase("true")) {
                                flag = true;
                            }
                            else if (!args[3].equalsIgnoreCase("false")) {
                                sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> useRange <true/false>");
                                return;
                            }
                            final String zn = this.pl.zoneManager.setUseRange(args[1], flag);
                            if (zn != null) {
                                sender.sendMessage(ChatColor.GREEN + "Successfully set useRange flag for " + zn + " to " + flag);
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> useRange <true/false>");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("setRange")) {
                        if (args.length == 4) {
                            int range = 0;
                            try {
                                range = Integer.parseInt(args[3]);
                            }
                            catch (NumberFormatException e3) {
                                sender.sendMessage(ChatColor.GREEN + "\"" + args[3] + "\" is not a valid number!");
                                return;
                            }
                            final String zn = this.pl.zoneManager.setRange(args[1], range);
                            if (zn != null) {
                                sender.sendMessage(ChatColor.GREEN + "Successfully set range for zone " + zn + " to " + range);
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> range <#Range>");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("setRangeFrom")) {
                        if (args.length == 4) {
                            if (!args[3].equalsIgnoreCase("zone") && !args[3].equalsIgnoreCase("custom")) {
                                sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> rangeFrom <custom/zone>");
                                return;
                            }
                            final RangeFrom flag2 = RangeFrom.get(args[3]);
                            final String zn = this.pl.zoneManager.setRangeFrom(args[1], flag2);
                            if (zn != null) {
                                sender.sendMessage(ChatColor.GREEN + "Successfully set range from " + flag2.getNormalString() + " for the zone " + zn);
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> rangeFrom <custom/zone>");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("setCustomRangeLocation")) {
                        if (sender instanceof Player) {
                            final String zn3 = this.pl.zoneManager.setCustomRangeLocation(args[1], ((Player)sender).getLocation());
                            if (zn3 != null) {
                                sender.sendMessage(ChatColor.GREEN + "Successfully set the custom location for the zone " + zn3);
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage("Only players can use that command");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("keepDirection")) {
                        if (args.length == 4) {
                            boolean flag = false;
                            if (args[3].equalsIgnoreCase("true")) {
                                flag = true;
                            }
                            else if (!args[3].equalsIgnoreCase("false")) {
                                sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> keepDirection <true/false>");
                                return;
                            }
                            final String zn = this.pl.zoneManager.setKeepDirection(args[1], flag);
                            if (zn != null) {
                                sender.sendMessage(ChatColor.GREEN + "Successfully set KeepDirection for zone " + zn + " to " + flag);
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> keepDirection <true/false>");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("mode")) {
                        if (args.length == 4) {
                            if (!args[3].equalsIgnoreCase("ground") && !args[3].equalsIgnoreCase("air") && !args[3].equalsIgnoreCase("top") && !args[3].equalsIgnoreCase("combined")) {
                                sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> mode <ground/air/top>");
                                return;
                            }
                            final SpawnOn flag3 = SpawnOn.get(args[3]);
                            final String zn = this.pl.zoneManager.setMode(args[1], flag3);
                            if (zn != null) {
                                sender.sendMessage(ChatColor.GREEN + "Successfully set mode for zone " + zn + " to " + flag3.getNormalString());
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> mode <ground/air/top>");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("setGroundBlocks")) {
                        if (args.length == 4) {
                            BlockData[] blocks = new BlockData[0];
                            if (!args[3].equalsIgnoreCase("clear")) {
                                blocks = StringTools.getBlockDataArray(args[3], ",");
                            }
                            final String zn = this.pl.zoneManager.setGroundBlocks(args[1], blocks);
                            if (zn != null) {
                                sender.sendMessage(ChatColor.GREEN + "Successfully set GroundBlocks for zone " + zn + " to " + Arrays.toString(blocks));
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> setGroundBlocks <Blocks(1,2,3...)>");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("setTopBlocks")) {
                        if (args.length == 4) {
                            BlockData[] blocks = new BlockData[0];
                            if (!args[3].equalsIgnoreCase("clear")) {
                                blocks = StringTools.getBlockDataArray(args[3], ",");
                            }
                            final String zn = this.pl.zoneManager.setTopBlocks(args[1], blocks);
                            if (zn != null) {
                                sender.sendMessage(ChatColor.GREEN + "Successfully set TopBlocks for zone " + zn + " to " + Arrays.toString(blocks));
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> setTopBlocks <Blocks(1,2,3...)>");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("setInvulnerability")) {
                        if (args.length == 4) {
                            int range = 0;
                            try {
                                range = Integer.parseInt(args[3]);
                            }
                            catch (NumberFormatException e3) {
                                sender.sendMessage(ChatColor.GREEN + "\"" + args[3] + "\" is not a valid number!");
                                return;
                            }
                            final String zn = this.pl.zoneManager.setInvulnerability(args[1], range);
                            if (zn != null) {
                                sender.sendMessage(ChatColor.GREEN + "Successfully set invulnerability for zone " + zn + " to " + range + "s");
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> setInvulnerability <#Seconds>");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("setUseKit")) {
                        if (args.length == 4) {
                            boolean flag = false;
                            if (args[3].equalsIgnoreCase("true")) {
                                flag = true;
                            }
                            else if (!args[3].equalsIgnoreCase("false")) {
                                sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> useKit <true/false>");
                                return;
                            }
                            final String zn = this.pl.zoneManager.setUseKit(args[1], flag);
                            if (zn != null) {
                                sender.sendMessage(ChatColor.GREEN + "Successfully set useKit flag for " + zn + " to " + flag);
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc option <ZoneName> setUseKit <true/false>");
                        }
                    }
                    else if (args[2].equalsIgnoreCase("setKit")) {
                        if (sender instanceof Player) {
                            final Player p2 = (Player)sender;
                            final Inventory inv = this.pl.zoneManager.getKit(args[1]);
                            if (inv != null) {
                                p2.openInventory(inv);
                                this.pl.events.kitEdit.put(p2.getName(), this.pl.zoneManager.getZoneName(args[1]));
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                    }
                    else {
                        sender.sendMessage(ChatColor.GREEN + "Invalid option! Use /rLoc option for help");
                    }
                }
                else if (args[0].equalsIgnoreCase("setType")) {
                    if (args.length == 3) {
                        final ZoneType type = ZoneType.getByString(args[2]);
                        if (type == null) {
                            sender.sendMessage(ChatColor.GREEN + "ZoneType can be tp/Teleport, p/Portal, ntp/NonTeleport");
                        }
                        else {
                            final String zn = this.pl.zoneManager.setType(args[1], type);
                            if (zn != null) {
                                sender.sendMessage(ChatColor.GREEN + "Set ZoneType for " + zn + " to " + type.getNormalString());
                            }
                            else {
                                sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                            }
                        }
                    }
                    else {
                        sender.sendMessage(ChatColor.GREEN + "Use /rLoc setType <Zone> <tp(Teleport)/p(Portal)/ntp(NonTeleport)>");
                    }
                }
                else if (args[0].equalsIgnoreCase("setPortalDest")) {
                    if (args.length == 3) {
                        final String zn3 = this.pl.zoneManager.setPortalDest(args[1], args[2]);
                        if (zn3 == null) {
                            sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                        }
                        else if (zn3.equalsIgnoreCase("??NonPortal")) {
                            sender.sendMessage(ChatColor.GREEN + "You need to set the portal zone to ZoneType portal first");
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc setType <Zone> <p/Portal>");
                        }
                        else if (zn3.equalsIgnoreCase("??NonDest")) {
                            sender.sendMessage(ChatColor.GREEN + "Could not find any destination zone by the name \"" + args[2] + "\"");
                        }
                        else if (zn3.equalsIgnoreCase("??NonTeleportDest")) {
                            sender.sendMessage(ChatColor.GREEN + "The destination zone needs to be a teleport zone");
                            sender.sendMessage(ChatColor.GREEN + "Use /rLoc setType <Zone> <tp/Teleport)>");
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Set portal destination for " + zn3.split("§")[0] + " to " + zn3.split("§")[1]);
                        }
                    }
                    else {
                        sender.sendMessage(ChatColor.GREEN + "Use /rLoc setPortalDest <Zone(Portal)> <Zone(Destination)>");
                    }
                }
                else if (args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("delete")) {
                    if (args.length == 2) {
                        final String zn3 = this.pl.zoneManager.removeZone(args[1]);
                        if (zn3 != null) {
                            sender.sendMessage(ChatColor.GREEN + "Successfully deleted zone " + zn3);
                        }
                        else {
                            sender.sendMessage(ChatColor.GREEN + "Could not find any zone by the name " + args[1]);
                        }
                    }
                    else {
                        sender.sendMessage(ChatColor.GREEN + "Use /rLoc del <ZoneName>");
                    }
                }
                else if (args[0].equalsIgnoreCase("list")) {
                    sender.sendMessage(this.pl.zoneManager.getList());
                }
                else {
                    sender.sendMessage(ChatColor.GREEN + "Unknown command, use /rLoc for help");
                }
            }
            else {
                sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use that command!");
            }
        }
        else if (label.equalsIgnoreCase("rSpawn")) {
            if (sender instanceof Player) {
                final Player p2 = (Player)sender;
                if (p2.hasPermission("RandomLocation.Use") || !this.pl.getConfig().getBoolean("Permissions.UsePermissions") || p2.hasPermission("RandomLocation.Admin") || p2.hasPermission("RandomLocation.UseCommand")) {
                    if (args.length == 1) {
                        this.pl.zoneManager.teleportPlayer(p2, (CommandSender)p2, args[0], TeleportSource.COMMAND);
                    }
                    else {
                        p2.sendMessage(ChatColor.GREEN + "用法: /rSpawn <区域名>");
                    }
                }
                else {
                    sender.sendMessage(ChatColor.DARK_RED + "你没有权限使用此命令!");
                }
            }
            else {
                sender.sendMessage("只有玩家可以使用这个指令");
            }
        }
        else if (label.equalsIgnoreCase("rReload")) {
            if (sender.hasPermission("RandomLocation.Admin")) {
                this.pl.reload();
                sender.sendMessage(ChatColor.GREEN + "Reloaded RandomLocation config");
            }
            else {
                sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use that command!");
            }
        }
        else if (label.equalsIgnoreCase("rPlayer")) {
            if (sender.hasPermission("RandomLocation.Admin")) {
                if (args.length == 2) {
                    final Player p2 = Bukkit.getPlayerExact(args[1]);
                    if (p2 != null && p2.isOnline()) {
                        this.pl.zoneManager.teleportPlayer(p2, sender, args[0], TeleportSource.OVERRIDE);
                        return;
                    }
                    sender.sendMessage(ChatColor.GREEN + "Could not find any online players by the name " + args[1]);
                }
                else {
                    sender.sendMessage(ChatColor.GREEN + "Use /rPlayer <ZoneName> <PlayerName>");
                }
            }
            else {
                sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use that command!");
            }
        }
    }
}
